<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 国际化实践指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border: 1px solid rgba(102, 126, 234, 0.3);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: attr(data-lang);
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #858585;
            text-transform: uppercase;
        }
        
        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            flex-shrink: 0;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 20px 0;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
        
        .file-tag {
            background: #f3f4f6;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 14px;
            color: #4b5563;
            display: inline-block;
            margin-right: 8px;
        }
        
        pre code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            line-height: 1.6;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    Spring Boot 国际化实践指南
                </h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    <i class="fas fa-globe-asia mr-2"></i>
                    构建多语言应用，让你的产品走向世界
                </p>
                <div class="mt-8 flex justify-center space-x-6">
                    <div class="text-center">
                        <i class="fas fa-language text-3xl mb-2"></i>
                        <p class="text-sm">多语言支持</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-cogs text-3xl mb-2"></i>
                        <p class="text-sm">灵活配置</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-rocket text-3xl mb-2"></i>
                        <p class="text-sm">快速实现</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-5xl mx-auto">
            
            <!-- Introduction -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover animate-fade-in">
                <p class="text-lg leading-relaxed text-gray-700">
                    在 Spring Boot 应用中实现国际化（i18n）是通过为不同语言和地区创建资源文件（properties 文件），并使用 Spring 提供的国际化支持来根据用户的区域设置加载适当的资源文件。让我们一步步探索如何实现这一功能。
                </p>
            </div>

            <!-- Architecture Diagram -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover">
                <h2 class="text-2xl font-bold mb-6 section-title">国际化架构概览</h2>
                <div class="mermaid">
                    graph TB
                        A[用户请求] -->|Accept-Language| B[Spring Boot应用]
                        B --> C[LocaleResolver]
                        C --> D[MessageSource]
                        D --> E[messages_zh.properties]
                        D --> F[messages_en.properties]
                        D --> G[messages_fr.properties]
                        E --> H[返回本地化内容]
                        F --> H
                        G --> H
                        style A fill:#667eea,stroke:#fff,color:#fff
                        style B fill:#764ba2,stroke:#fff,color:#fff
                        style H fill:#4ade80,stroke:#fff,color:#fff
                </div>
            </div>

            <!-- Step 1 -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover">
                <div class="flex items-start mb-6">
                    <div class="step-number">1</div>
                    <h2 class="text-2xl font-bold ml-4">创建国际化资源文件</h2>
                </div>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    首先，在 <code class="bg-gray-100 px-2 py-1 rounded">src/main/resources</code> 目录下创建多个 <code class="bg-gray-100 px-2 py-1 rounded">properties</code> 文件，每个文件对应一种语言和地区：
                </p>
                
                <div class="grid md:grid-cols-2 gap-4 mb-6">
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <i class="fas fa-file-alt text-purple-600 mr-2"></i>
                        <span class="file-tag">messages.properties</span>
                        <span class="text-sm text-gray-600">默认语言</span>
                    </div>
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <i class="fas fa-file-alt text-blue-600 mr-2"></i>
                        <span class="file-tag">messages_en.properties</span>
                        <span class="text-sm text-gray-600">英文</span>
                    </div>
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <i class="fas fa-file-alt text-red-600 mr-2"></i>
                        <span class="file-tag">messages_zh.properties</span>
                        <span class="text-sm text-gray-600">中文</span>
                    </div>
                    <div class="bg-gray-50 p-4 rounded-lg">
                        <i class="fas fa-file-alt text-green-600 mr-2"></i>
                        <span class="file-tag">messages_fr.properties</span>
                        <span class="text-sm text-gray-600">法语</span>
                    </div>
                </div>

                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold mb-2 text-gray-800">
                            <i class="fas fa-code mr-2 text-purple-600"></i>messages.properties（默认）
                        </h4>
                        <div class="code-block p-4" data-lang="properties">
                            <pre><code>greeting=Hello!
farewell=Goodbye!</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold mb-2 text-gray-800">
                            <i class="fas fa-code mr-2 text-red-600"></i>messages_zh.properties（中文）
                        </h4>
                        <div class="code-block p-4" data-lang="properties">
                            <pre><code>greeting=你好！
farewell=再见！</code></pre>
                        </div>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold mb-2 text-gray-800">
                            <i class="fas fa-code mr-2 text-green-600"></i>messages_fr.properties（法语）
                        </h4>
                        <div class="code-block p-4" data-lang="properties">
                            <pre><code>greeting=Bonjour!
farewell=Au revoir!</code></pre>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Step 2 -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover">
                <div class="flex items-start mb-6">
                    <div class="step-number">2</div>
                    <h2 class="text-2xl font-bold ml-4">配置国际化支持</h2>
                </div>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    在 Spring Boot 中，你需要配置 <code class="bg-gray-100 px-2 py-1 rounded">MessageSource</code> 来加载这些资源文件。你可以在配置类中定义 <code class="bg-gray-100 px-2 py-1 rounded">MessageSource</code> bean。
                </p>
                
                <div class="code-block p-4" data-lang="java">
                    <pre><code>import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;

import java.util.Locale;

@Configuration
public class InternationalizationConfig extends AcceptHeaderLocaleResolver {

    @Bean
    public MessageSource messageSource() {
        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setBasename("classpath:messages");
        messageSource.setDefaultEncoding("UTF-8");
        return messageSource;
    }

    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        String headerLang = request.getHeader("Accept-Language");
        return headerLang == null || headerLang.isEmpty()
                ? Locale.getDefault()
                : Locale.forLanguageTag(headerLang);
    }
}</code></pre>
                </div>
            </div>

            <!-- Step 3 -->
            <div class="bg-white rounded-xl shadow-lg p-8 mb-8 card-hover">
                <div class="flex items-start mb-6">
                    <div class="step-number">3</div>
                    <h2 class="text-2xl font-bold ml-4">使用国际化资源</h2>
                </div>
                
                <p class="text-gray-700 mb-6 leading-relaxed">
                    在代码中使用 <code class="bg-gray-100 px-2 py-1 rounded">MessageSource</code> 或 <code class="bg-gray-100 px-2 py-1 rounded">@Autowired</code> 自动注入的 <code class="bg-gray-100 px-2 py-1 rounded">messageSource</code> 来获取国际化信息：
                </p>
                
                <div class="code-block p-4" data-lang="java">
                    <pre><code>import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import java.util.Locale;

@RestController
public class GreetingController {

    @Autowired
    private MessageSource messageSource;

    @GetMapping("/greeting")
    public String getGreeting(@RequestHeader(name = "Accept-Language", required = false) Locale locale) {
        return messageSource.getMessage("greeting", null, locale);
    }
}</code></pre>
                </div>
            </div>

            <!-- Step 4 -->
            <div class="